package com.gopay.gass.service.impl.bank;

import org.springframework.stereotype.Service;

import com.gopay.common.domain.bank.BcdlMessage;
import com.gopay.gass.constants.SameBank;
import com.gopay.gass.domain.GassMainOrder;
import com.gopay.gass.domain.GassOrderDtl;
import com.gopay.gass.service.impl.GassPayRequestServiceImpl;


/**
 * Created by HJY on 2015/3/20.
 */
@Service("icbcGassPayRequestService")
public class ICBCGassPayRequestServiceImpl extends GassPayRequestServiceImpl {

//    private static Logger logger = LoggerFactory.getLogger("ICBC");
//
//    @Override
//    public synchronized GassPayRespMessage processReq(GassPayReqMessage reqMsg){
//        logger.info("------[银企直连调用"+getBankName()+"]start-------orderId:"+reqMsg.getGopayOrderId());
//        GassOrderView orderView = null;
//        GassPayRespMessage respMessage = null;
//        try {
//            orderView = checkAndSaveOrder(reqMsg);
//        } catch (GassServiceException e) {
//            e.printStackTrace();
//            return createRespMsg("",ResultCode.FAILED,e.getErrorMsg());
//        }
//        logger.info("------[银企直连调用"+getBankName()+"]saved-------orderId:"+reqMsg.getGopayOrderId());
//        //付款
//        respMessage = pay(orderView.getMainOrder(),orderView.getOrderDtl());
//        return  respMessage;
//    }

//    private GassPayRespMessage pay(GassMainOrder main,GassOrderDtl dtl){
//        String gassId = main.getGassId();
//        ResultCode resultCode = ResultCode.FAILED;
//        String resultMsg = "付款失败";
//        BcdlMessage message = null;
//        try {
//            message = createPayMsg(main,dtl);
//            message.setPbocBankName("中国工商银行");
//            message.setPobcBankCode("102");
//        } catch (Exception e) {
//            e.printStackTrace();
//            return createRespMsg(gassId, resultCode, "组装报文失败");
//        }
//
//        BcdlResult result = null;
//        try {
//            //调用银企直连
//            result = bcdlPay(message);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return createRespMsg(gassId, resultCode, "调用银企直连失败");
//        }
//        if(result != null){
//            if(result.isSuccess()){
//                resultCode = ResultCode.ACCEPTED;
//                resultMsg = "付款已受理";
//            }else{
//            	resultMsg = result.getResultCode()+":"+result.getBankRetMsg();
//            }
//        }else{
//            resultMsg = "银企直连返回空";
//        }
//        main.setStlmDes(resultMsg);
//        main.setStlmStatus(resultCode.getValue());
//        main.setOrderRespTm(new Date());
//        main.setLastUpdTs(new Date());
//        gassOrderService.updateMainOrder(main);
//        logger.info("------[银企直连调用工行]pay-------orderId:"+main.getGopayOrderId()+" resultMsg:"+resultMsg);
//        return createRespMsg(gassId,resultCode,resultMsg);
//    }

    protected SameBank getSameBank(String recvBankName){
        if(recvBankName.indexOf("工商") !=-1 || recvBankName.indexOf("工行")!=-1){
            return SameBank.NO;
        }
        return SameBank.YES;
    }

	@Override
	protected BcdlMessage buildBcdlMessage(GassMainOrder main, GassOrderDtl dtl) {
		BcdlMessage message = super.createBaseBcdlMessage(main, dtl);
        message.setPbocBankName(getBankName());
        message.setPobcBankCode("102");
		return message;
	}

	@Override
	protected String getBankName() {
		return "中国工商银行";
	}
}
